import userService from '@/common/service/userService';
import store from '../store/store';

export default {
  async init () {
    let vm = this;
    if (Object.keys(store.state.userInfo).length === 0) {
      vm.userInit();
    }
    vm.getUserList();
    vm.checkUser();
  },
  checkUser () {
    if (store.state.userInfo.role && [2, 3, 4, 5].indexOf(parseInt(store.state.userInfo.role)) === -1) {
      alert('请退出股权管理平台');
      document.getElementById('mask').className = '';
      location.href = '/share.html#/share';
    };
  },
  async userInit () {
    let data, vm = this;
    //  await userService.simulalteLogin(18616502568);
    //  boss 15067371009 manager 18616502568 cy 18621824165
      data = await userService.loginInfo();
      if (data.data.success) {
        store.commit('setUserInfo', data.data.data);
        vm.checkUser();
      }
  },
  async getUserList () {
    let data1, data2, data3, _userList = [];
      data1 = await userService.getUserList(3);
      data2 = await userService.getUserList(4);
      data3 = await userService.getUserList(5);
      _userList = data1.data.data.concat(data2.data.data.concat(data3.data.data));
        store.commit('setUserList', _userList);
  }
};
